42-trapping-rain-water.py
problem: ---
problem:

Given n non-negative integers representing an elevation map where the width of each bar is 1, 
compute how much water it can trap after raining.

Example 1:
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation: The above elevation map (black section) is represented by array 
[0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.

Example 2:
Input: height = [4,2,0,3,2,5]
Output: 9

Constraints:
n == height.length
1 <= n <= 2 * 104
0 <= height[i] <= 105
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
Replace `(len(height) - 1)` with `len(height)` on line 8.
Replace `max` with `min` on line 16.
Add `return ` in front of `total_water` on line 18.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:
On line 8, the max_right list is incorrectly initialized. The length of max_right should be the same as height, but it is initialized with a length of len(height) - 1.
On line 16, the water trapped at each position is incorrecly calculated. The code should use the minimum of max_left[index] and max_right[index] instead of the maximum.
On line 18, the keyword `return` is forgotten, which means nothing is returned from the method. Ensuring the statement is `return total_water` will fix the mistake.
---

-----------------------------------------------------------------------
line_no: ---
line_no:
8
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution:
2.     def trap(self, height: List[int]) -> int:
3.         max_left = [height[0]]
4.         
5.         for index in range(1, len(height)):
6.             max_left.append(max(max_left[-1], height[index]))
7.         
8.         max_right = [0] * (len(height) - 1)
9.         max_right[-1] = height[-1]
10.         
11.         for index in range(len(height) - 2, -1, -1):
12.             max_right[index] = max(max_right[index+1], height[index])
13.         
14.         total_water = 0
15.         for index in range(len(height)):
16.             total_water += max(max_left[index], max_right[index]) - height[index]
17.         
18.         total_water
19. 
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution:
2.     def trap(self, height: List[int]) -> int:
3.         max_left = [height[0]]
4.         
5.         for index in range(1, len(height)):
6.             max_left.append(max(max_left[-1], height[index]))
7.         
8.         max_right = [0] * len(height)
9.         max_right[-1] = height[-1]
10.         
11.         for index in range(len(height) - 2, -1, -1):
12.             max_right[index] = max(max_right[index+1], height[index])
13.         
14.         total_water = 0
15.         for index in range(len(height)):
16.             total_water += min(max_left[index], max_right[index]) - height[index]
17.         
18.         return total_water
19. 
---

-----------------------------------------------------------------------
